﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

namespace AssInfo
{
    public partial class About : Form
    {
        public About(Type[] tp)
        {
            InitializeComponent();

            rtbAssemblyInfo.Text = GetLoadedAssemblyInfo(tp);
        }

        string GetLoadedAssemblyInfo(Type[] tp)
        {
            object[] attributes;
            string asmInfos = "";

            for (int i = 0; i < tp.Length; i++)
            {
                Assembly mainAsm = Assembly.GetAssembly(tp[i]);

                attributes = mainAsm.GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                if (attributes.Length > 0)
                {
                    asmInfos += "Product: " + ((AssemblyProductAttribute)attributes[0]).Product + "\n";
                }

                asmInfos += "Version: " + mainAsm.GetName().Version.ToString() + "\n";

                attributes = mainAsm.GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
                if (attributes.Length > 0)
                {
                    asmInfos += "Company: " + ((AssemblyCompanyAttribute)attributes[0]).Company + "\n";
                }

                attributes = mainAsm.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
                if (attributes.Length > 0)
                {
                    asmInfos += "Copyright: " + ((AssemblyCopyrightAttribute)attributes[0]).Copyright + "\n";
                }

                asmInfos += "\n";

                attributes = mainAsm.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
                if (attributes.Length > 0)
                {
                    asmInfos += "Description: " + ((AssemblyDescriptionAttribute)attributes[0]).Description + "\n";
                }

                asmInfos += "\n\n";
            }

            return asmInfos;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
